package com.apes.framework.plugin.workflow.domain;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.scm.rbac.model.User;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 抄送消息
 *
 * @author bb
 * @create 2019-4-26 11:05:37
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CarbonCopyMessage.CONST_TABLE_NAME)
public class CarbonCopyMessage extends Model {

    public static final String CONST_TABLE_NAME = "wf_carbon_copy_message";


    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "消息编码", prefix = "M")
    private String id;

    @Comment("抄送人")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "from_origin", referencedColumnName = "id")
    private User fromOrigin;

    @Comment("抄送对象")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "to_target", referencedColumnName = "id")
    private User toTarget;

    @Column(name = "source_business_type", length = 64)
    @Comment("来源单据类型")
    private String sourceBusinessType;

    @Column(name = "source_business_key", length = 64)
    @Comment("来源单据号码")
    private String sourceBusinessKey;

    @Column(name = "process_definition_name", length = 64)
    @Comment("流程名称")
    private String processDefinitionName;

    @Column(name = "form_id", length = 64)
    @Comment("来源表单")
    private String formId;

    @Column(name = "api", length = 64)
    @Comment("调用api")
    private String api;

    @Column(name = "operate", length = 64)
    @Comment("操作")
    private String operate;

    @Column(name = "content", length = 4000)
    @Comment("消息内容")
    private String content;


    @States(name = "阅读状态", values = {
            @State(id = "0", name = "未阅"),
            @State(id = "1", name = "已阅"),
    })
    @Column(name = "checked", nullable = false, columnDefinition = "number(1,0) default 0")
    private boolean checked = true;
}
